﻿using SIR.Common;
using SIR.Common.Condition;
using SIR.Entities.Interfaces;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace SIR.Entities.Implementations
{
	/// <summary>
	/// Describes a group of patterns
	/// </summary>
	public class PatternDescriptionGroup : Entity, IPatternDescriptionGroup
	{
		/// <summary>
		/// Gets or sets the name of the pattern description group
		/// </summary>
		[DatabaseAccess(DatabaseAccessRights.ReadWrite)]
		public string Name { get; set; }

		private IReadOnlyCollection<IPatternDescription> _patterns;

		/// <summary>
		/// Gets the list of patterns within the group
		/// </summary>
		[DatabaseAccess(DatabaseAccessRights.None)]
		public IReadOnlyCollection<IPatternDescription> Patterns
		{
			get
			{
				if (_patterns == null)
				{
					_patterns = new ReadOnlyCollection<PatternDescription>(DAL.DataServer.Find<PatternDescription>(
						new Predicate("PatternDescriptionGroupId", Id, PredicateOperator.EqualTo)).Results);
				}
				return _patterns;
			}
		}
	}
}
